{{#useAndroidMavenGradlePlugin}}
group = '{{groupId}}'
project.version = '{{artifactVersion}}'
{{/useAndroidMavenGradlePlugin}}

buildscript {

    ext.kotlin_version = '1.5.20'
    ext.swagger_annotations_version = "1.6.2"
    ext.gson_version = "2.8.6"
    ext.volley_version = "1.2.0"
    ext.junit_version = "4.13.2"
    ext.robolectric_version = "4.5.1"
    ext.concurrent_unit_version = "0.4.6"

    repositories {
        mavenLocal()
        google()
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:7.4.2'
        {{#useAndroidMavenGradlePlugin}}
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        {{/useAndroidMavenGradlePlugin}}
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
{{#useAndroidMavenGradlePlugin}}
apply plugin: 'com.github.dcendents.android-maven'
{{/useAndroidMavenGradlePlugin}}

android {
    compileSdkVersion 30
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
    }
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        abortOnError false
    }

    // Rename the aar correctly
    libraryVariants.all { variant ->
        variant.outputs.all { output ->
            if (outputFile != null && outputFileName.endsWith('.aar')) {
                outputFileName = "${archivesBaseName}-${version}.aar"
            }
        }
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
    implementation "com.google.code.gson:gson:$gson_version"
    implementation "com.android.volley:volley:${volley_version}"
    testImplementation "junit:junit:$junit_version"
    testImplementation "org.robolectric:robolectric:${robolectric_version}"
    testImplementation "net.jodah:concurrentunit:${concurrent_unit_version}"
    {{#generateRoomModels}}
    annotationProcessor "androidx.room:room-runtime:2.3.0"
    implementation "androidx.room:room-runtime:2.3.0"
    {{/generateRoomModels}}
}

afterEvaluate {
    android.libraryVariants.all { variant ->
        def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
        task.description = "Create jar artifact for ${variant.name}"
        task.dependsOn variant.javaCompile
        task.from variant.javaCompile.destinationDirectory
        task.destinationDirectory = project.file("${project.buildDir}/outputs/jar")
        task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar"
        artifacts.add('archives', task);
    }
}

{{#useAndroidMavenGradlePlugin}}
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

artifacts {
    archives sourcesJar
}
{{/useAndroidMavenGradlePlugin}}
